package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Livestocks;
import com.ruoyi.system.service.ILivestocksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 牧畜信息Controller
 * 
 * @author ruoyi
 * @date 2023-09-21
 */
@RestController
@RequestMapping("/system/livestocks")
public class LivestocksController extends BaseController
{
    @Autowired
    private ILivestocksService livestocksService;

    /**
     * 查询牧畜信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:livestocks:list')")
    @GetMapping("/list")
    public TableDataInfo list(Livestocks livestocks)
    {
        startPage();
        List<Livestocks> list = livestocksService.selectLivestocksList(livestocks);
        return getDataTable(list);
    }

    /**
     * 导出牧畜信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:livestocks:export')")
    @Log(title = "牧畜信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Livestocks livestocks)
    {
        List<Livestocks> list = livestocksService.selectLivestocksList(livestocks);
        ExcelUtil<Livestocks> util = new ExcelUtil<Livestocks>(Livestocks.class);
        util.exportExcel(response, list, "牧畜信息数据");
    }

    /**
     * 获取牧畜信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:livestocks:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(livestocksService.selectLivestocksById(id));
    }

    /**
     * 新增牧畜信息
     */
    @PreAuthorize("@ss.hasPermi('system:livestocks:add')")
    @Log(title = "牧畜信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Livestocks livestocks)
    {
        return toAjax(livestocksService.insertLivestocks(livestocks));
    }

    /**
     * 修改牧畜信息
     */
    @PreAuthorize("@ss.hasPermi('system:livestocks:edit')")
    @Log(title = "牧畜信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Livestocks livestocks)
    {
        return toAjax(livestocksService.updateLivestocks(livestocks));
    }

    /**
     * 删除牧畜信息
     */
    @PreAuthorize("@ss.hasPermi('system:livestocks:remove')")
    @Log(title = "牧畜信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(livestocksService.deleteLivestocksByIds(ids));
    }
}
